<template>
	<view>
		<!--自定义导航栏-->
		<uni-nav-bar :statusBar="true" @clickLeft="back" @clickRight="submit" left-icon="back" right-text="发布">
			<view class="u-f-ajc tarCss" @click="changLook">{{yinsi}}
				<view class="icon iconfont icon-xialazhankai"></view>
			</view>
		</uni-nav-bar>
		<!--多行输入框-->
		<view class="uni-textarea">
			<textarea v-model="text" placeholder="说一句话吧" />
			</view>
		<!--上传多图-->
		<uploud-images @uploud="uploud"></uploud-images>
		<!--弹出公告-->
		<uni-popup :show="true" ref="popup" type="dialog">
			<view class="gonggao">
				<view class="u-f-ajc">
					<image src="../../static/demo/touxiang.jpg"></image>
				</view>
				<view>1:蜡笔小新</view>
				<view>2:大头儿子小头爸爸</view>
				<view>3:隔壁王叔叔(嘿嘿嘿)</view>
				<view>随意发挥想象</view>
				<button type="default" @click="open('2')">朕知道了</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
	import uploudImages from '@/components/common/uploud-images.vue'
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
	import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
	
	const changLook = ['所有人可见', '仅自己可见']

	export default {
		data() {
			return {
				yinsi: '所有人可见',
				text:'',
				imageList:[],
				isget:true
			}
		},
		//初始化完成后调用
		onReady() {
			this.open('1');
		},
		//监听返回事件
		onBackPress() {
			if(!this.text && this.imageList.length<1){
				return;
			}
			this.baocun();
			return this.isget;
		},
		methods: {
			//返回
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			//发布
			submit() {
				console.log("发布")
			},
			//切换
			changLook() {
				uni.showActionSheet({
					itemList: changLook,
					success: (res) => {
						this.yinsi = changLook[res.tapIndex]
					}
				})
			},
			uploud(arr){
				this.imageList=arr
			},
			open(type){
				switch(type){
					case '1':
					 this.$refs.popup.open()
					 break;
					 case '2':
					 this.$refs.popup.close()
					 break;
				}
			   
			},
			//保存为草稿
			baocun(){
				uni.showModal({
					content: '是否要保存为草稿？',
					cancelText: '不保存',
					confirmText: '保存',
					success: res => {
						if(res.confirm){
							
						}else{
							
						}
						this.isget=false
						uni.navigateBack({
							delta: 1
						});
					}
				});
			}
		},
		components: {
			uniNavBar,
			uploudImages,
			uniPopup,
			uniPopupMessage,
			uniPopupDialog
		}
	}
</script>

<style lang="scss">
	.tarCss {
		margin: 0 auto; //为了居中
	}
	
	.uni-textarea{
		border: 1rpx solid #EEEEEE;
	}
	
	.gonggao{
		background-color: #FFFFFF;
		.u-f-ajc{
			image{
				height: 300rpx;
				margin-bottom: 20rpx;
			}
		}
		view{
			color: #333333;
			font-size: 40rpx;
		}
		button{
			margin-top: 20rpx;
			background-color: #ffff00;
			color: #333333;
			font-size: 40rpx;
			font-weight: bold;
		}
	}
</style>
